//
//  UIImageView+WebImage.swift
//  SwiftWeibo
//
//  Created by Lausen on 2017/4/25.
//  Copyright © 2017年 id. All rights reserved.
//

import SDWebImage

extension UIImageView{
    
    func lau_image(urlString: String?,placeholderImage: UIImage?,isAvatar: Bool = false) {
        
        guard let urlString = urlString,
            let url = URL(string: urlString) else {
            
            //如果穿件来的url是空的,那么就直接使用占位图片并且直接返回
            image = UIImage(named: "avatar_default_big")
            
            return
        }
        
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { (image, _, _, _) in
            
            if isAvatar { //如果是头像的话,裁切圆角
                
                self.image = image?.cz_avatarImage(size: self.bounds.size)
            }
        }
    }
}
